{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">

                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('bannerAdd')}');">
                            <i class="fa fa-plus"></i> 添加轮播图
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
                <!--搜索开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="banner_type" id="n_range" lay-search="" class="layui-input">
                                <option value="">全部类型</option>
                                <option value="1">首页轮播图</option>
                                <option value="2">论坛页轮播图</option>
                                <option value="3">派逊天地首页轮播图</option>
                                <option value="4">关于派逊页轮播图</option>
                                <option value="5">企业资质页轮播图</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="banner_status" lay-search="" class="layui-input">
                                <option value="">全部状态</option>
                                <option value="1">上架</option>
                                <option value="2">下架</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text" id="n_title" class="layui-input search" name="n_title" placeholder="轮播图名称"/>
                        </div>
                        <div class="layui-input-inline" style="margin-left: 10px;">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty" lay-submit="" lay-filter="LAY-search">
                                重置
                            </button>
                        </div>
                    </div>
                </div>
                <!--搜索结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.banner_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>

                    <!--状态显示模板-->
                    <script type="text/html" id="statBar">
                        {{# if(d.banner_status == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.banner_status == 2){ }}
                        已下架
                        {{# } }}
                    </script>
                    <script type="text/html" id="banner_type">
                        {{# if(d.banner_type == 1){ }}
                        首页轮播图
                        {{# } }}
                        {{# if(d.banner_type == 2){ }}
                        论坛页轮播图
                        {{# } }}
                        {{# if(d.banner_type == 3){ }}
                        派逊天地首页轮播图
                        {{# } }}
                        {{# if(d.banner_type == 4){ }}
                        关于派逊页轮播图
                        {{# } }}
                        {{# if(d.banner_type == 5){ }}
                        企业资质页轮播图
                        {{# } }}
                    </script>

                    <script type="text/html" id="statBar1">
                        {{# if(d.banner_type == 1){ }}
                            {{# if(d.banner_cate == 1){ }}
                            内链
                            {{# } }}
                            {{# if(d.banner_cate == 2){ }}
                            外链
                            {{# } }}
                            {{# if(d.banner_cate == 3){ }}
                            图文
                            {{# } }}
                        {{# } }}
                        {{# if(d.banner_type > 1){ }}
                            图片
                        {{# } }}
                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('bannerEdit')}?banner_id={{d.banner_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        <!--<a href="javascript:;" onclick="wk.href('{:url('bannerDetail')}?lunbo_id={{d.lunbo_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看详情"><i class="fa fa-search"></i></a>-->
                        {{# if(d.banner_status == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.banner_id}}','{:url('bannerDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架"><i class="fa fa-arrow-down">下架</i></a>
                        {{# } }}
                        {{# if(d.banner_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.banner_id}}','{:url('bannerOn')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架"><i class="fa fa-arrow-up">上架</i></a>
                        {{# } }}
                        <!--<a href="javascript:;" onclick="wk.confirm('{{d.banner_id}}','{:url('bannerDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>-->
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Banner/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                  {type:'numbers', width: 60, title: '序号'}
                , {field: 'banner_title', width: '', title: '标题', align: 'center'}
                , {field: 'banner_img', width: 90, title: '缩略图', align: 'center', templet: '#imgTpl'}
                , {field: 'banner_status', width: 80, title: '状态', align: 'center', toolbar: '#statBar'}
                , {field: 'banner_sort', width: 130, title: '排序（可编辑）', align: 'center', edit: 'test'}
                , {field: 'banner_time', width: 160, title: '最后操作时间', align: 'center'}
                , {field: 'banner_cate', width: 60, title: '分类', align: 'center', toolbar: '#statBar1'}
                , {field: 'banner_type', width: '', title: '类型', align: 'center', toolbar: '#banner_type'}
                , {field: 'banner_link', width: '', title: '外链地址', align: 'center'}
                , {field: 'good_name', width: '', title: '商品名字', align: 'center'}
                , {fixed: 'right', width: 200, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });

        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
            wk.change(data.banner_id,"{:url('updateSort')}",field,value);
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['banner_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>